package com.example.springboot.controller;

import com.example.springboot.common.Result;
import com.example.springboot.controller.request.RBookPageRequest;
import com.example.springboot.entity.RBook;
import com.example.springboot.service.IRBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author:Domen
 * @Date:2023/11/7 16:36
 */

@CrossOrigin
@RestController
@Controller
@RequestMapping("/rBook")
public class RBookController {
    @Autowired
    IRBookService rBookService;

    @PutMapping("/save")
    public Result save(@RequestBody RBook obj){
        rBookService.save(obj);
        return Result.success();
    }

    @PutMapping("/update")
    public Result update(@RequestBody RBook obj){
        rBookService.update(obj);
        return Result.success();
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id){
        rBookService.deleteById(id);
        return Result.success();
    }

    @GetMapping("/list")
    public Result list(){
       List<RBook> list = rBookService.list();
       return Result.success(list);        //包装一下，使返回的结果更加规范
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        RBook obj = rBookService.getById(id);
        return Result.success(obj);
    }

    @GetMapping("/page")
    public Result page(RBookPageRequest pageRequest){
        return Result.success(rBookService.page(pageRequest));        //包装一下，使返回的结果更加规范
    }

}
